package com.itheima.edu.info.manage.dao;

import com.itheima.edu.info.manage.domain.student;

public class studentDao {
    private static student[] stus = new student[5];

    public boolean addstudent(student stu) {

        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            student student = stus[i];
            if (student == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            stus[index] = stu;
            return true;
        }
    }

    public student[] findAllstudent() {
        return stus;
    }

    public void deletestudentByid(String delid) {
        int index = getindex(delid);
        stus[index] = null;

    }

    public int getindex(String id) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            student student = studentDao.stus[i];
            if (student != null && student.getSid().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public void updatestudent(String updateid, student newstu) {
        int index = getindex(updateid);
        stus[index] = newstu;
    }
}
